﻿using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Supp;
using MediatR;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Supp
{
    public class QuerySupplierHandler : IRequestHandler<QuerySupplierCommand, ApiResult<List<Supplier>>>
    {
        private readonly IBaseRepository<Supplier> suRep;

        public QuerySupplierHandler(IBaseRepository<Supplier> suRep)
        {
            this.suRep = suRep;
        }
        public Task<ApiResult<List<Supplier>>> Handle(QuerySupplierCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Supplier>> result = new ApiResult<List<Supplier>>();
            var list = suRep.GetAll().Where(x => x.ProductId == request.ProductId&&x.Type==request.Type);
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
